<template>
    <div class="wh-100 px-12 overflow-auto pb-60" style="background-color: #fff">
        <!--职位概览-->
        <div class="w-100 my-12 h_350p b_1_d1d1d1 b_r_5" v-loading="boxloading1">
            <div class="wh-100">
                <div class="wh-100 pt-20 px-28 d-flex">
                    <div class="mt-28 d-flex-center h_200p w_200p" style="float: left">
                        <el-image :src="companyDetails.logo" class="h_120p w_120p" alt="企业logo">
                            <div slot="error" class="image-slot d-flex-around-center h_120p w_120p" style="background-color: #f5f7fa">
                                <i class="el-icon-picture-outline"></i>
                            </div>
                        </el-image>
                        <!--            <img :src="companyDetails.logo" width="100px" height="100px" alt="企业logo">-->
                    </div>
                    <div class="d-flex flex-column ml-40 flex-1" style="height: 100%; overflow: scroll">
                        <div class="mb-12">
                            <span class="fs-18 fw-7 mr-32">{{ companyDetails.name }}</span>
                            <!--                            <a :href="'https://www.qcc.com/web/search?key=' + companyDetails.name" target="_blank" class="fs-12">企查查</a>-->
                            <a class="cursor-pointer fs-12" :href="'https://www.tianyancha.com/search?key=' + companyDetails.name" target="_blank">天眼查</a>
                        </div>
                        <div class="fs-14 mb-12 mt-12">
                            <span>{{ companyDetails.quality }}</span>
                            <span class="ml-28">{{ companyDetails.type }}</span>
                        </div>
                        <div class="fs-14 mb-12">
                            <span>招聘状态：{{ companyDetails.status }}</span>
                            <span class="ml-28">在招职位：{{ companyDetails.positionNumber }} 个</span>
                        </div>
                        <div class="fs-14 mb-12">
                            <span>联系人：{{ companyDetails.attnName }}</span>
                            <span class="ml-28">联系电话：{{ companyDetails.attnPhone }}</span>
                        </div>
                        <span class="fs-14 mb-12">公司地址：{{ companyDetails.address }}</span>
                        <span class="fs-14 mb-12" style="word-wrap: break-word; word-break: break-all">公司简介：{{ companyDetails.introduction }}</span>
                    </div>
                    <div class="w_100p" style="float: right; height: 100%">
                        <el-button @click="goBack">返回</el-button>
                    </div>
                    <!--          <div class="debugger-bor" style="float: right;width:200px;height: 100%;border: 1px solid #e3d4d7;" @click="goBack">返回</div>-->
                </div>
            </div>
        </div>
        <!--审核情况-->
        <div class="w-100" v-loading="boxloading3">
            <div class="px-28 h_40p lh_40p fs-16 fw-6 b_b_1_e5e5e5">审核情况</div>
            <div class="wh-100 d-flex">
                <div class="w-50 mt-12 fs-16 px-28">
                    <div>证明材料</div>
                    <div class="my-12">
                        <el-image class="ml-12 mr-28 h_200p w_200p" :src="auditList.enterpriseSupportingMaterial" alt="单位证件" :preview-src-list="image_change">
                            <div slot="error" class="image-slot fs-12 d-flex-around-center h_200p w_200p" style="background-color: #f5f7fa">
                                <i class="el-icon-picture-outline">单位证件</i>
                            </div>
                        </el-image>
                        <el-image :src="auditList.attnSupportingMaterial" alt="经办人证件" class="mr-28 h_200p w_200p" :preview-src-list="image_change">
                            <div slot="error" class="image-slot fs-12 d-flex-around-center h_200p w_200p" style="background-color: #f5f7fa">
                                <i class="el-icon-picture-outline">经办人证件</i>
                            </div>
                        </el-image>
                        <el-image :src="auditList.attnSupportingLetter" alt="经办人证件" class="mr-28 h_200p w_200p" :preview-src-list="image_change">
                            <div slot="error" class="image-slot fs-12 d-flex-around-center h_200p w_200p" style="background-color: #f5f7fa">
                                <i class="el-icon-picture-outline">授权公函</i>
                            </div>
                        </el-image>
                    </div>
                    <!--        <div>-->
                    <!--          <img src="" alt="单位证件">-->
                    <!--          <img src="" alt="经办人证件" class="ml-28">-->
                    <!--        </div>-->
                    <div class="mt-12 fs-14 d-flex flex-column">
                        <div class="my-12">
                            <span class="mr-12">当前状态：</span>
                            <span v-if="auditList.reviewStatus == '待审核'" style="color: blue">待审核</span>
                            <span v-else-if="auditList.reviewStatus == '审核通过'" style="color: green">审核通过</span>
                            <span v-else-if="auditList.reviewStatus == '审核未通过'" style="color: red">审核不通过</span>
                            <span v-else>暂无数据</span>
                        </div>
                        <div v-if="showSubmit" class="">
                            <div>
                                <span class="mr-12">审核人员：</span>
                                <span>{{ auditList.auditName ? auditList.auditName : '暂无数据' }}</span>
                            </div>
                        </div>
                    </div>
                    <div v-if="showSubmit" class="mt-12">
                        <div>
                            <span class="fs-14 mr-12">审核选择</span>
                            <el-radio-group v-model="auditForm.isPass">
                                <el-radio :label="true">通过</el-radio>
                                <el-radio :label="false">不通过</el-radio>
                            </el-radio-group>
                        </div>
                        <div>
                            <Input
                                v-if="auditForm.isPass === false"
                                class="w_300p m_t_12p m_l_70p"
                                v-model="auditForm.auditFail"
                                type="textarea"
                                :rows="4"
                                maxlength="200"
                                show-word-limit
                                placeholder="输入不通过的原因"
                            />
                            <Button type="primary" class="w_100p h_30p m_l_70p m_t_12p" style="margin-top: 12px; display: block" @click="submitForReview" :loading="buttonLoading">提交</Button>
                        </div>
                    </div>
                </div>
                <div v-if="showCause" class="w-50 mt-12 fs-16 px-28" style="border-left: 1px dashed #d1d1d1">
                    <div class="w-100 d-flex-align-center" style="height: 20%">
                        <div style="width: 10%">招聘专业:</div>
                        <div style="width: 90%">{{ auditList.professional }}</div>
                    </div>
                    <div class="w-100 d-flex" style="height: 80%">
                        <div style="width: 10%">申请原因:</div>
                        <div style="width: 90%" class="overflow-auto-hidden">{{ auditList.applicationReason }}</div>
                    </div>
                </div>
            </div>
        </div>
        <!--tab表格-->
        <div class="mt-12 px-20 d-flex-between-center fs-14 h_50p b_b_1_ecf0f6">
            <!--tab头部-->
            <div class="d-flex-align-center">
                <div v-if="showPostion" :class="activeTab === 1 ? 'tab-cut' : ''" @click="unitCheckIn(1)">在招职位</div>
                <div :class="activeTab === 2 ? 'tab-cut' : ''" class="ml-48" @click="unitCheckIn(2)">申请记录</div>
                <div :class="activeTab === 3 ? 'tab-cut' : ''" class="ml-48" @click="unitCheckIn(3)">参与过的活动</div>
            </div>
        </div>
        <!--在招职位-->
        <div v-if="activeTab === 1" class="overflow-auto mt-12 px-20 h_500p" style="align-items: center">
            <div class="bor-base mt-12 mb-12 d-flex flex-row fs-14" style="align-items: center" v-for="item in positionList" :key="item.id">
                <div class="h-100 px-12 py-12 w_100 flex-1">
                    <div class="d-flex flex-row mb-12">
                        <div class="flex-1">{{ item.positionName ? item.positionName : '--' }}</div>
                        <div class="flex-1">月薪：{{ item.minSalary ? item.minSalary : '--' }}K-{{ item.maxSalary ? item.maxSalary : '--' }}K</div>
                        <div class="flex-1">更新于：{{ item.updateTime ? item.updateTime : '--' }}</div>
                        <div class="flex-2"></div>
                    </div>
                    <div class="d-flex flex-row">
                        <div class="flex-1">工作城市：{{ item.workCity ? item.workCity : '--' }}</div>
                        <div class="flex-1">学历：{{ item.education ? item.education : '--' }}</div>
                        <div class="flex-1">职务类别：{{ item.positionType ? item.positionType : '--' }}</div>
                        <div class="flex-2 pl-12">专业：{{ item.proRequire ? item.proRequire : '--' }}</div>
                    </div>
                </div>
                <div class="h-100 d-flex d-flex-center px-12 py-12 w_100p"><Button type="primary" class="h_30p w_60p" @click="viewJobDetails(item)">详情</Button></div>
            </div>
        </div>
        <!--申请记录-->
        <div v-if="activeTab === 2" class="overflow-auto mt-12 px-20 h_500p">
            <el-table :data="recordList" :header-cell-style="{ background: '#f0f0f0', color: '#606266' }" empty-text="暂无数据">
                <el-table-column property="name" label="学校名称" width="150"></el-table-column>
                <el-table-column property="activityType" label="审核类型" width="200"></el-table-column>
                <el-table-column property="reviewStatus" label="审核状态"></el-table-column>
                <el-table-column property="auditFail" label="审核原因" align="center">
                    <template slot-scope="scope">{{ scope.row.auditFail ? scope.row.auditFail : '--' }}</template>
                </el-table-column>
                <el-table-column property="auditTime" label="审核时间"></el-table-column>
            </el-table>
        </div>
        <!--参与过的活动-->
        <div v-if="activeTab === 3" class="overflow-auto mt-12 px-20 h_500p">
            <div class="bor-base-b mt-28 d-flex flex-column fs-14" v-for="item in activityList" :key="item.id">
                <div class="px-12 py-12 fw-6" style="">
                    {{ item.activityName ? item.activityName : '--' }}
                </div>
                <div class="px-12 pb-12 d-flex">
                    <div style="color: #999999" class="w_100-120p">
                        <div class="mb-8">报名时间： {{ item.applicationStartTime ? item.applicationStartTime : '--' }} - {{ item.applicationEndTime ? item.applicationEndTime : '--' }}</div>
                        <div class="mb-8">举办场地： {{ item.venue ? item.venue : '--' }}</div>
                        <div>举办学校： {{ item.activityOrganizer ? item.activityOrganizer : '--' }}</div>
                    </div>
                    <div style="color: #1d8ce0" class="w_100p d-flex d-flex-center" @click="enterAssemblyHall(item)">进入会场</div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import {
    getRequestRecordAPI,
    pageActivitiesAPI,
    getPositionsAPI,
    getPositionsDetailsAPI,
    getPositionsProveAPI,
    auditEnterpriseAPI,
    doubleSelectPassAPI,
    getAuditDetailsNewAPI
} from '../../../api/bys/recruitmentManagement';
import { getImgById } from '@/directive/img-auth';
import { updateVal } from '../../../util/ObjectUtil';

let handleMenu = e => {
    e.preventDefault();
    console.log('禁止右键');
};

export default {
    data() {
        return {
            image_change: [],
            activeTab: 2,
            type: 2,
            enterpriseId: '',
            schoolId: '',
            shDoubleElectionId: '',
            boxloading1: false,
            boxloading2: false,
            boxloading3: false,
            isShow: true,
            status: '',
            reason: '',
            jobDescription: '',
            generalRegulationsID: '',
            buttonLoading: false,
            recordList: [
                {
                    schoolName: '-',
                    activityType: '-',
                    auditStatus: '-',
                    auditReason: '-',
                    auditTime: '-'
                }
            ],
            skillTag: [
                { id: '1', label: 'java' },
                { id: '2', label: 'mysql' }
            ],
            chapterContentList: {
                education: '本科生毕业', //学历要求
                enterpriseAttnName: '企业经办人名称', //企业经办人名称
                enterpriseName: '企业名称', //企业名称
                major: '计算机类通信类电子信息类控制科学类自动化类', //专业要求
                positionDesc: '职位描述', //职位描述
                positionName: '中兴5G网络优化工程师', //职位名称
                positionType: '网络优化工程师', //职位类别
                publishTime: '2023-11-05 23:07', //职位发布时间
                recruitNum: 50, //招聘人数
                recruitUnit: '河南明和通信技术有限公司', //招聘单位（招聘企业）
                salaryRange: '6k-8k', //月薪范围
                skill: 'java', //技能标签
                workCity: '河南郑州', //工作城市
                workNature: '全职' //工作性质
            }, //职位概览列表
            auditList: {
                enterpriseSupportingMaterial: '', //单位证件
                attnSupportingMaterial: '', //经办人证件
                attnSupportingLetter: '', //授权公函
                auditName: '', //审核人员
                reviewStatus: '', //审核状态
                applicationReason: '', //入驻原因
                professional: '' //入驻专业
            },
            positionList: [],
            activityList: [],
            activityParams: {
                pageNumber: 1,
                pageSize: 10,
                enterpriseId: '',
                order: '',
                sort: ''
            },
            positionParams: {
                pageNumber: 1,
                pageSize: 10,
                enterpriseId: '',
                order: '',
                sort: ''
            },
            companyDetails: {
                address: '', //单位详细地址
                attnName: '', //企业联系人
                attnPhone: '', //企业联系人电话
                industry: '', //单位所属行业
                introduction: '', //公司简介
                logo: '', //企业logo
                name: '', //公司名称
                positionNumber: 0, //在招职位个数
                quality: '', //单位性质
                status: '', //招聘状态
                type: '' //单位类型
            },
            activityTotal: 0,
            auditForm: {
                enterpriseId: '',
                isPass: true,
                auditFail: ''
            },
            showSubmit: false,
            showPostion: false,
            showCause: false
        };
    },
    computed: {},
    mounted() {
        this.showSubmit=true;
        if (this.$route.query.optionType) {
            this.showSubmit = this.$route.query.optionType !== '参会用人单位and查看';
            if (this.$route.query.optionType === '参会用人单位and查看' || this.$route.query.optionType === '参会用人单位and审核') {
                this.showPostion = true;
                this.activeTab = 1;
            }
        }
        this.getRequestRecord();
        this.pageActivities();
        this.getPositions();
        this.getPositionsDetails();
        this.getPositionsProve();

        document.addEventListener('contextmenu', handleMenu);
    },
    created() {
        this.enterpriseId = this.$route.query.id;
        if (this.$route.query.schoolId) {
            this.schoolId = this.$route.query.schoolId;
        }
        if (this.$route.query.shDoubleElectionId) {
            this.shDoubleElectionId = this.$route.query.shDoubleElectionId;
        }
    },
    destroyed() {
        document.removeEventListener('contextmenu', handleMenu);
    },
    methods: {
        // region TODO 提交审核
        submitForReview() {
            debugger;
            if (this.shDoubleElectionId) {
                console.log(this.shDoubleElectionId, '双选会企业审核');
                if (this.auditForm.isPass) {
                    this.auditForm.auditFail = '';
                }
                let queryForm = {
                    enterpriseId: this.enterpriseId,
                    isPass: this.auditForm.isPass,
                    failReason: this.auditForm.auditFail,
                    doubleElectionId: this.shDoubleElectionId
                };
                doubleSelectPassAPI(queryForm).then(res => {
                    if (res.success) {
                        this.$message.success(res.message);
                        this.$router.back();
                    }
                });
            } else {
                console.log(this.shDoubleElectionId, '企业审核');
                if (this.auditForm.isPass) {
                    this.auditForm.auditFail = '';
                }
                let params = {
                    schoolId: this.schoolId,
                    enterpriseId: this.enterpriseId,
                    isPass: this.auditForm.isPass,
                    failReason: this.auditForm.auditFail
                };
                auditEnterpriseAPI(params).then(res => {
                    if (res.success) {
                        this.$message.success(res.message);
                        this.$router.back();
                    }
                });
            }
        },
        // endregion
        // region TODO 企业证明信息
        getPositionsProve() {
            if (this.shDoubleElectionId) {
                getPositionsProveAPI({
                    enterpriseId: this.enterpriseId,
                    doubleElectionId: this.shDoubleElectionId
                }).then(res => {
                  console.log(res, '企业证明信息')
                    if (res.success) {
                        console.log(res, '企业证明信息');
                        this.auditList = res?.result || [];
                        this.image_change = [];
                        if (res?.result?.enterpriseSupportingMaterial) {
                            this.image_change.push(res?.result?.enterpriseSupportingMaterial);
                        }
                        if (res?.result?.attnSupportingMaterial) {
                            this.image_change.push(res?.result?.attnSupportingMaterial);
                        }
                        if (res?.result?.attnSupportingLetter) {
                            this.image_change.push(res?.result?.attnSupportingLetter);
                        }
                        console.log(this.image_change, '企业证明信息');
                    }
                });
            } else {
                getAuditDetailsNewAPI({
                    enterpriseId: this.enterpriseId,
                    schoolId: this.schoolId
                }).then(async res => {
                    if (res.success) {
                        updateVal(this.auditList,res?.result)
                        // this.auditList = res?.result || [];
                        this.showCause = true;
                      console.log(res, '企业证明信息2222');

                      if (res?.result?.enterpriseSupportingMaterial) {
                        this.image_change.push(res?.result?.enterpriseSupportingMaterial);
                      }
                      if (res?.result?.attnSupportingMaterial) {
                        this.image_change.push(res?.result?.attnSupportingMaterial);
                      }
                      if (res?.result?.attnSupportingLetter) {
                        this.image_change.push(res?.result?.attnSupportingLetter);
                      }
                      console.log(this.image_change, '企业证明信息11111');

                    }
                });
            }
        },
        // endregion
        // region TODO 企业参与过的活动
        pageActivities() {
            this.activityParams.enterpriseId = this.enterpriseId;
            pageActivitiesAPI(this.activityParams).then(res => {
                if (res.success) {
                    console.log(res, '企业参与过的活动');
                    this.activityList = res?.result?.result || [];
                    this.activityTotal = res?.result?.total || 0;
                }
            });
        },
        // endregion
        // region TODO 企业在招职位
        getPositions() {
            this.positionParams.enterpriseId = this.enterpriseId;
            getPositionsAPI({ ...this.positionParams, doubleId: this.shDoubleElectionId }).then(res => {
                if (res.success) {
                    console.log(res, '企业在招职位');
                    this.positionList = res.result;
                }
            });
        },
        // endregion
        // region TODO 企业详情
        getPositionsDetails() {
            getPositionsDetailsAPI({ enterpriseId: this.enterpriseId }).then(res => {
                if (res.result) {
                    console.log(res, '企业详情');
                    this.companyDetails = res?.result || '';
                }
            });
        },
        // endregion
        // region TODO 申请记录
        getRequestRecord() {
            getRequestRecordAPI({
                enterpriseId: this.enterpriseId
            }).then(res => {
                if (res.success) {
                    console.log(res, '审核记录');
                    this.recordList = res?.result || [];
                    this.dialogTableVisible = true;
                } else {
                    this.recordList = [];
                    this.dialogTableVisible = true;
                }
            });
        },
        // endregion
        // region TODO 返回
        goBack() {
            this.$router.back();
        },

        // endregion
        // region TODO tab切换
        unitCheckIn(data) {
            this.activeTab = data;
        },
        // region TODO 查看该行职位的具体数据
        viewJobDetails(row) {
            sessionStorage.setItem(
                'positionDetail',
                JSON.stringify({
                    dataRow: row
                })
            );
            this.$router.push({
                name: 'PositionDetail',
                params: {
                    dataRow: row
                }
            });
        },
        // endregion
        // endregion
        enterAssemblyHall(dataRow) {
            // this.$router.push({name:'UnitDetails',query:{id:id,shDoubleElectionId:this.pageParams.shDoubleElectionId}})
            this.$router.push({ name: 'DoubleSelectionMeetingDetails', params: { dataRow: dataRow } });
        }
        // getAuditProveDetails() {
        //   getAuditProveDetailsAPI({
        //     positionId:this.positionId}).then((res) => {
        //     console.log(res,'证明材料')
        //     this.auditList = res?.result || ''
        //   })
    }
};
</script>
<style scoped>
.job-overview {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-row-gap: 10px;
}
.tab-cut {
    color: #0094fa;
    height: 50px;
    line-height: 50px;
    border-bottom: 3px solid #0094fa;
}

.job-description div:not(:first-child) {
    margin-top: 12px;
}

.audit-status {
    font-size: 14px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-row-gap: 20px;
}
</style>
